home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 1 / Amiga Tools.iso / egs-tools / egs_dev-disk / egsdemos / egsexamples / gadgets / select / select.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-06  |  4.5 KB  |  206 lines

  1. /*
  2. *  $
  3. *  $ FILE     : select.c
  4. *  $ VERSION  : 1
  5. *  $ REVISION : 7
  6. *  $ DATE     : 08-Dec-93 15:05
  7. *  $
  8. *  $ Author   : mvk
  9. *  $
  10. *
  11. *  This is an example for gbselect.library
  12. *
  13. *  It creates an select Gadget with four items.
  14. *  The item 4 is Activate if the window is opened or
  15. *  resized.
  16. *
  17. */
  18. /*
  19.     Related Files: gbselect.doc, gbselect.h <- Our Scrollbox gadget
  20.            egsintui.doc, egsintui.h  <- window stuff
  21.            egsgadbox.doc, egsgadbox.h <- The actual gadbox
  22.  main.c
  23. */
  24.  
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <exec/types.h>
  28. #include <dos/dos.h>
  29. #include <exec/memory.h>
  30. #include <proto/dos.h>
  31. #include <proto/exec.h>
  32. #include <egs/egs.h>
  33. #include <egs/egsintui.h>
  34. #include <egs/egsgadbox.h>
  35. #include <egs/egb/gbselect.h>
  36. #include <egs/proto/all.h>
  37.  
  38. /*
  39. **  Protos
  40. */
  41. EI_WindowPtr CreateSelectWindow (EI_WindowPtr win);
  42. APTR My_FindGadget(EB_GadContext GadCon,WORD ID);
  43. void Clean_Exit (void);
  44.  
  45. struct Library *EGSIntuiBase=NULL;         // EGSIntuition
  46. struct Library *EGBSelectBase=NULL;        // SelectBox
  47. struct Library *EGBBase=NULL;              // gadbox
  48.  
  49. EB_GadContext   GadCon;
  50. EI_WindowPtr    window;
  51. EB_StrArray     elems={"Text 0","Text 1","Text 2","Text 3",NULL};
  52.  
  53.  
  54. void main (void) {
  55.    EI_EIntuiMsgPtr msg;
  56.    int class;
  57.    struct EI_Gadget *iaddress;
  58.  
  59.    if (!(EGSIntuiBase = OpenLibrary ("egsintui.library",0))) {
  60.      printf ("Unable open egsintui.library.\n");
  61.      Clean_Exit ();
  62.    }
  63.    if (!(EGBSelectBase = OpenLibrary ("egb/gbselect.library",0))) {
  64.      printf ("Unable open gbmenuselect.library.\n");
  65.      Clean_Exit ();
  66.    }
  67.    if (!(EGBBase = OpenLibrary ("egsgadbox.library",0))) {
  68.      printf ("Unable open egsgadbox.library.\n");
  69.      Clean_Exit ();
  70.    }
  71.  
  72.    if (!(window = CreateSelectWindow (NULL))) {
  73.      printf ("Unable to open Window.\n");
  74.      Clean_Exit ();
  75.    }
  76.  
  77.    for (;;) {  // Forever
  78.  
  79.      Wait (1<<window->UserPort->mp_SigBit);  // wait for our signals
  80.  
  81.      while ( (msg=(struct EI_EIntuiMsg *) GetMsg (window->UserPort)) != NULL) {
  82.  
  83.        class = msg->Class;
  84.        iaddress = (struct EI_Gadget *)msg->IAddress;
  85.  
  86.  
  87.        switch (class) {
  88.  
  89.      case EI_iCLOSEWINDOW:
  90.        ReplyMsg ( (struct Message *)msg);
  91.         Clean_Exit ();
  92.      break;
  93.                   // User has begun to resize window
  94.      case EI_iSIZEVERIFY:
  95.          EI_LockIntuition ();
  96.          EI_RemoveGList (window,GadCon->First, GadCon->Num);
  97.          EB_DeleteGadContext (GadCon);
  98.          EI_UnlockIntuition ();
  99.        ReplyMsg ( (struct Message *)msg);
  100.      break;
  101.  
  102.      case EI_iNEWSIZE:
  103.  
  104.          EI_LockIntuition ();
  105.          window = CreateSelectWindow (window);
  106.          EI_AddGList ( window,GadCon->First,GadCon->Num );
  107.          EI_UnlockIntuition ();
  108.        ReplyMsg ( (struct Message *)msg);
  109.       break;
  110.  
  111.      case EI_iGADGETUP:
  112.         printf("Gadget no=%d \n",((EGB_SelectGadgetPtr)iaddress)->Sel);
  113.  
  114.        ReplyMsg ( (struct Message *)msg);
  115.       break;
  116.  
  117.        }
  118.      }
  119.    }
  120.  }
  121.  
  122. /*
  123. **
  124. ** CreateSelectGadgets
  125. **
  126. */
  127. EI_WindowPtr CreateSelectWindow (EI_WindowPtr win)
  128. {
  129.  
  130.    EB_GadBoxPtr root;
  131.  
  132.    GadCon = EB_CreateGadContext (NULL,NULL,-1,-1);
  133.  
  134.    root = EB_CreateHorizBox (GadCon);
  135.    EB_AddLastSon (root,EB_CreateHorizFill (GadCon,EB_FILL_ALL,0));
  136.  
  137.    EB_AddLastSon (root,EGB_CreateTextSelectGadget(GadCon,0x300,&elems));
  138.  
  139.    EB_AddLastSon (root,EB_CreateHorizFill (GadCon,EB_FILL_ALL,0));
  140.  
  141.    root = EB_CreateMasterWindow (GadCon,win,root);
  142.  
  143.    if (EB_ProcessGadBoxes (GadCon,root))
  144.    {
  145.  
  146.     if (win==NULL) {
  147.       GadCon->NewWin->IDCMPFlags        |= EI_iCLOSEWINDOW | EI_iSIZEVERIFY |
  148.                        EI_iNEWSIZE     | EI_iGADGETUP |
  149.                        EI_iGADGETDOWN;
  150.  
  151.       GadCon->NewWin->Bordef.SysGadgets |= (EI_WINDOWCLOSE)|(EI_WINDOWSIZE);
  152.  
  153.      /*
  154.      **
  155.      **  EI_GIMMEZEROZERO is required for a sizeable GadBox
  156.      **
  157.      */
  158.  
  159.       GadCon->NewWin->Flags             |= (EI_SIZEBBOTTOM | EI_GIMMEZEROZERO);
  160.  
  161.       win=EI_OpenWindow (GadCon->NewWin);
  162.  
  163.     }
  164.  
  165.     EGB_ModifySelectGadget(win,My_FindGadget(GadCon,0x300),3);
  166.  
  167.     return (win);
  168.  
  169.   }else
  170.     return NULL;
  171. }
  172.  
  173.  
  174. /*
  175. **
  176. ** This function searched for Subgadget in a MasterGadget,
  177. ** because all Gadgets are in a MasterWindow.
  178. **
  179. */
  180. APTR My_FindGadget(EB_GadContext GadCon,WORD ID)
  181. {
  182.     /*
  183.     ** MasterGadPtr because the window is create with
  184.     ** EB_CreateMasterWindow function
  185.     */
  186.     return( EB_FindGadget(
  187.         ((EI_MasterGadPtr)GadCon->First)->FirstSon,
  188.         ((EI_MasterGadPtr)GadCon->First)->NumSons,ID));
  189. }
  190.  
  191. void Clean_Exit (void) {
  192.  
  193.     if (window)
  194.       EI_CloseWindow (window);
  195.     if (GadCon)
  196.       EB_DeleteGadContext (GadCon);
  197.     if (EGBBase)
  198.       CloseLibrary (EGBBase);
  199.     if (EGBSelectBase)
  200.       CloseLibrary (EGBSelectBase);
  201.     if (EGSIntuiBase)
  202.       CloseLibrary (EGSIntuiBase);
  203.  
  204.     exit (0);
  205. }
  206.